package com.free.compilation.controller;

import com.free.common.core.utils.poi.ExcelUtil;
import com.free.common.core.web.controller.BaseController;
import com.free.common.core.web.domain.AjaxResult;
import com.free.common.core.web.page.TableDataInfo;
import com.free.common.log.annotation.Log;
import com.free.common.log.enums.BusinessType;
import com.free.compilation.domain.ZoneCompilationStep;
import com.free.compilation.service.ZoneCompilationStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合集步骤Controller
 *
 * @author free
 * @date 2023-07-25
 */
@RestController
@RequestMapping("/step")
public class ZoneCompilationStepController extends BaseController {
    @Autowired
    private ZoneCompilationStepService zoneCompilationStepService;

    /**
     * 查询合集步骤列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ZoneCompilationStep zoneCompilationStep) {
        startPage();
        List<ZoneCompilationStep> list = zoneCompilationStepService.selectZoneCompilationStepList(zoneCompilationStep);
        return getDataTable(list);
    }

    /**
     * 导出合集步骤列表
     */
    @Log(title = "合集步骤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZoneCompilationStep zoneCompilationStep) {
        List<ZoneCompilationStep> list = zoneCompilationStepService.selectZoneCompilationStepList(zoneCompilationStep);
        ExcelUtil<ZoneCompilationStep> util = new ExcelUtil<ZoneCompilationStep>(ZoneCompilationStep.class);
        util.exportExcel(response, list, "合集步骤数据");
    }

    /**
     * 获取合集步骤详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zoneCompilationStepService.selectZoneCompilationStepById(id));
    }

    /**
     * 新增合集步骤
     */
    @Log(title = "合集步骤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZoneCompilationStep zoneCompilationStep) {
        return success(zoneCompilationStepService.insertZoneCompilationStep(zoneCompilationStep));
    }

    /**
     * 修改合集步骤
     */
    @Log(title = "合集步骤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZoneCompilationStep zoneCompilationStep) {
        return toAjax(zoneCompilationStepService.updateZoneCompilationStep(zoneCompilationStep));
    }

    /**
     * 删除合集步骤
     */
    @Log(title = "合集步骤", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(zoneCompilationStepService.deleteZoneCompilationStepByIds(ids));
    }

    /**
     * 删除合集步骤
     */
    @Log(title = "查询没有引用章节的记录", businessType = BusinessType.DELETE)
    @GetMapping("/getNotQuoteChapter/{compilationId}")
    public AjaxResult notQuoteChapter(@PathVariable Long compilationId) {
        return success(zoneCompilationStepService.notQuoteChapter(compilationId));
    }
}
